﻿using jbt.CodeCandy.AsTrEAM.Client;
using jbt.CodeCandy.AsTrEAM.WebApi.WCF.Properties;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

namespace jbt.CodeCandy.AsTrEAM.WebApi.WCF.Controllers
{
    /// <summary>
    /// REST API controller what connects to an <see cref="IStreamManagerService"/>.
    /// </summary>
    public partial class StreamManagerController : ApiController
    {
        private string StreamManagerServiceUrl
        {
            get
            {
                return Settings.Default.StreamManagerServiceUrl;
            }
        }

        /// <summary>
        /// Deletes the stream with the specified identifier.
        /// </summary>
        /// <param name="id">
        /// Unique identifier of stream to delete.
        /// </param>
        /// <returns>
        /// Result of delete.
        /// </returns>
        public HttpResponseMessage Delete(string id)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Returns the stream with the specified identifier.
        /// </summary>
        /// <param name="id">
        /// Unique identifier of stream to return.
        /// </param>
        /// <returns>
        /// The stream with the specified identifier.
        /// </returns>
        public async Task<HttpResponseMessage> Get(string id)
        {
            var response = await StreamManagerClient.WCF.Get(StreamManagerServiceUrl, id);

            return response;
        }

        /// <summary>
        /// Creates a new stream.
        /// </summary>
        /// <returns>
        /// Result of create.
        /// </returns>
        public async Task<HttpResponseMessage> Post()
        {
            var response = await StreamManagerClient.WCF.Post(StreamManagerServiceUrl, Request);

            return response;
        }
    }
}